// EOInteger.cs created with MonoDevelop
// User: awilliam at 1:28 PM 9/25/2008
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//

using System;

namespace Whitemice.EOMono
{
  public class EOInteger : EOValue
  {
    protected int val;
    
    public EOInteger() : base()
    {
    }
    
    public EOInteger(int val) : base()
    {
      this.val = val;
    }
    
    public EOInteger(EOInteger val) : base()
    {
      this.Value = val.Value;
    }
    
    public static implicit operator EOInteger(int v) 
    {
      return new EOInteger(v);
    }
    
    public static implicit operator int(EOInteger v)
    {
      return Convert.ToInt32(v.Value);
    }
    
    public override bool Equals(object v)
    {
      if (v is int)
      {
        return (Convert.ToInt32(v) == val);
      } else if (v is Whitemice.EOMono.IEOValue)
        {
          return ((v as IEOValue).Value == this.Value);
        }
      return false;
    }
    
    public override int GetHashCode()
    {
      return val;
    }
    
    public override object Value
    {
      get 
      { 
        if (IsNull) return null;
        return val; 
      }
      set 
      { 
        if (value == null)
        {
          IsNull = true;
        } else
          {
            IsNull = false;
            val = Convert.ToInt32(value); 
          }
      }
    } // end Value
    
    public override string SQLValue()
    {
      if (IsNull) return "NULL";
      return val.ToString();
    }
  }
}
